package factory.demo2;

import factory.demo1.entity.AwardInfo;
import factory.demo1.entity.ResponseResult;
import factory.demo1.service.IFreeGoods;

/**
 * 发奖品接口
 *
 * @author 1
 * @version 1.0
 * @description: TODO
 * @date 2024-08-28 15:02
 */
public class DeliverController {
    /**
     * 按照类型的不同发放商品
     */
    public  static ResponseResult awardToUser2(AwardInfo awardInfo) {
        //根据类型获取工厂
        FreeGoodsFactory goodsFactory = FreeGoodsFactoryMap.getParserFactory(awardInfo.getAwardType());
        //从工厂中获取对应的实例
        IFreeGoods instance = goodsFactory.getInstance();
        //发放对应的奖品
        return instance.sendFreeGoods(awardInfo);
    }


    public static void main(String[] args) {
        //发放折扣券
        test1();
        //发放小礼品
        test2();
    }

    public static void test1(){
        //发放折扣券
        AwardInfo awardInfo = new AwardInfo();
        awardInfo.setUid("1001");
        awardInfo.setAwardNumber("101010");
        awardInfo.setAwardType(1);
        ResponseResult responseResult = awardToUser2(awardInfo);
        System.out.println(responseResult);
    }

    public static void test2(){
        //发放小礼品
        AwardInfo awardInfo = new AwardInfo();
        awardInfo.setUid("1001");
        awardInfo.setAwardNumber("101010");
        awardInfo.setAwardType(2);
        ResponseResult responseResult = awardToUser2(awardInfo);
        System.out.println(responseResult);
    }


}
